package com.example.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.time.Year;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sun.java_cup.internal.runtime.Symbol;

@WebServlet("/CalcServelt")

public class CalcServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();

		String num1 = req.getParameter("number1");
		String num2 = req.getParameter("number2");
		String y1 = req.getParameter("yunsuan");
		int n1 = Integer.parseInt(num1);
		int n2 = Integer.parseInt(num2);

		if (y1.equals("+")) {
			int sum = n1 + n2;
			String s1=String.valueOf(sum);
			pw.write(s1);
		} else if (y1.equals("-")) {
			int sum = n1 - n2;
			String s1=String.valueOf(sum);
			pw.write(s1);
		} else if (y1.equals("*")) {
			int sum = n1 * n2;
			String s1=String.valueOf(sum);
			pw.write(s1);
		} else if (y1.equals("/")) {
			int sum = n1 / n2;
			String s1=String.valueOf(sum);
			pw.write(s1);
		}
		else {
			pw.write("运算符输入错误，请重新输入");
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}